#import "AbstractLayoutView.h"

@implementation AbstractLayoutView

- (id)initWithFrame:(CGRect)frame
{
    return [self initWithFrame:frame spacing:0 leftMargin:0 rightMargin:0
            topMargin:0 bottomMargin:0
            hAlignment:UIControlContentHorizontalAlignmentCenter
            vAlignment:UIControlContentVerticalAlignmentCenter];
}

- (id)initWithFrame:(CGRect)frame spacing:(int)s
{
    return [self initWithFrame:frame spacing:s leftMargin:0 rightMargin:0
            topMargin:0 bottomMargin:0
            hAlignment:UIControlContentHorizontalAlignmentCenter
            vAlignment:UIControlContentVerticalAlignmentCenter];
}

- (id)initWithFrame:(CGRect)frame spacing:(int)s leftMargin:(int)lm
        rightMargin:(int)rm topMargin:(int)tm bottomMargin:(int)bm
{
    return [self initWithFrame:frame spacing:s leftMargin:lm rightMargin:rm
            topMargin:tm bottomMargin:bm
            hAlignment:UIControlContentHorizontalAlignmentCenter
            vAlignment:UIControlContentVerticalAlignmentCenter];    
}

- (id)initWithFrame:(CGRect)frame spacing:(int)s leftMargin:(int)lm
    rightMargin:(int)rm topMargin:(int)tm bottomMargin:(int)bm
    hAlignment:(UIControlContentHorizontalAlignment)ha
    vAlignment:(UIControlContentVerticalAlignment)va
{
    if (self = [super initWithFrame:frame])
    {
        spacing = s;
        leftMargin = lm;
        rightMargin = rm;
        topMargin = tm;
        bottomMargin = bm;
        hAlignment = ha;
        vAlignment = va;
    }
    return self;
}

- (void)setSize
{
    self.autoresizesSubviews = NO;
    [self sizeToFit];
    self.autoresizesSubviews = YES;
}

- (void)setSizeWithWidth:(int)w
{
    self.autoresizesSubviews = NO;
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, w,
                            [self sizeThatFits:self.frame.size].height);
    self.autoresizesSubviews = YES;
}

- (void)setSizeWithHeight:(int)h
{
    self.autoresizesSubviews = NO;
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,
                            [self sizeThatFits:self.frame.size].width, h);
    self.autoresizesSubviews = YES;
}

- (CGSize)layoutSubviewsEffectively:(BOOL)effectively
{
    return CGSizeZero;
}

- (void)layoutSubviews
{
    [self layoutSubviewsEffectively:YES];
}

- (CGSize)sizeThatFits:(CGSize)size
{
    return [self layoutSubviewsEffectively:NO];
}

@end
